package com.ruoyi.baoming.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.baoming.domain.TbZsbExamRegistration;
import com.ruoyi.baoming.service.impl.TbZsbExamRegistrationServiceImpl;
import com.ruoyi.chengkao.domain.CkCandidateRegistration;
import com.ruoyi.chengkao.service.impl.CkCandidateRegistrationServiceImpl;
import com.ruoyi.gaokao.controller.GkCandidateRegistrationController;
import com.ruoyi.gaokao.domain.GkCandidateRegistration;
import com.ruoyi.gaokao.mapper.GkCandidateRegistrationMapper;
import com.ruoyi.gaokao.service.impl.GkCandidateRegistrationServiceImpl;
import com.ruoyi.zhongkao.domain.ZkCandidateRegistration;
import com.ruoyi.zhongkao.service.impl.ZkCandidateRegistrationServiceImpl;
import com.ruoyi.zikao.domain.ZikaoCandidateRegistration;
import com.ruoyi.zikao.service.impl.ZikaoCandidateRegistrationServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.baoming.domain.ExamCandidate;
import com.ruoyi.baoming.service.IExamCandidateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 考生信息Controller
 * 
 * @author xiaosong
 * @date 2024-11-20
 */
@Api(tags = "考试管理-考生信息")
@RestController
@RequestMapping("/baoming/candidate")
public class ExamCandidateController extends BaseController
{
    @Autowired
    private IExamCandidateService examCandidateService;
    @Autowired
    private CkCandidateRegistrationServiceImpl ckCandidateRegistrationService;
    @Autowired
    private TbZsbExamRegistrationServiceImpl tbZsbExamRegistrationService;
    @Autowired
    private GkCandidateRegistrationServiceImpl gkCandidateRegistrationService;
    @Autowired
    private ZkCandidateRegistrationServiceImpl zkCandidateRegistrationService;
    @Autowired
    private ZikaoCandidateRegistrationServiceImpl zikaoCandidateRegistrationService;

    /**
     * 查询考生信息列表
     */
    @PreAuthorize("@ss.hasPermi('baoming:candidate:list')")
    @GetMapping("/list")
    @ApiOperation("考试考生信息管理 - 分页查询列表")
    public TableDataInfo list(ExamCandidate examCandidate)
    {
        startPage();
        List<ExamCandidate> list = examCandidateService.selectExamCandidateList(examCandidate);
        return getDataTable(list);
    }

    /**
     * 导出考生信息列表
     */
    @PreAuthorize("@ss.hasPermi('baoming:candidate:export')")
    @Log(title = "考生信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("考试考生信息管理 - 导出数据")
    public void export(HttpServletResponse response, ExamCandidate examCandidate)
    {
        List<ExamCandidate> list = examCandidateService.selectExamCandidateList(examCandidate);
        ExcelUtil<ExamCandidate> util = new ExcelUtil<ExamCandidate>(ExamCandidate.class);
        util.exportExcel(response, list, "考生信息数据");
    }

    /**
     * 获取考生信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('baoming:candidate:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("考试考生信息管理 - 根据ID获取详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(examCandidateService.selectExamCandidateById(id));
    }

    /**
     * 新增考生信息
     */
    @PreAuthorize("@ss.hasPermi('baoming:candidate:add')")
    @Log(title = "考生信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("考试考生信息管理 - 新增数据")
    public AjaxResult add(@RequestBody ExamCandidate examCandidate)
    {
        return toAjax(examCandidateService.insertExamCandidate(examCandidate));
    }

    /**
     * 修改考生信息
     */
    @PreAuthorize("@ss.hasPermi('baoming:candidate:edit')")
    @Log(title = "考生信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("考试考生信息管理 - 修改数据")
    public AjaxResult edit(@RequestBody ExamCandidate examCandidate)
    {
        return toAjax(examCandidateService.updateExamCandidate(examCandidate));
    }

    /**
     * 删除考生信息
     */
    @PreAuthorize("@ss.hasPermi('baoming:candidate:remove')")
    @Log(title = "考生信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("考试考生信息管理 - 删除数据")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(examCandidateService.deleteExamCandidateByIds(ids));
    }

    /**
     * 根据考生身份证号查询报名信息（ck_candidate_registration）和志愿报名信息（tb_zsb_exam_registration）
     * 返回 JSON 对象格式： { "ck_exam": [...], "zsb_exam": [...] }
     */
    @GetMapping("/examInfo/{idNumber}")
    @ApiOperation("考试考生信息管理 - getExamInfo")
    public AjaxResult getExamInfo(@PathVariable("idNumber") String idNumber) {
        CkCandidateRegistration ckExamList = ckCandidateRegistrationService.selectCkCandidateRegistrationByIdNumber(idNumber);
        TbZsbExamRegistration zsbExamList = tbZsbExamRegistrationService.selectTbZsbExamRegistrationByIdNumber(idNumber);
        // 高考信息查询
        GkCandidateRegistration gkExamList = gkCandidateRegistrationService.selectGkCandidateRegistrationByIdNumber(idNumber);
        ZkCandidateRegistration zkExamList = zkCandidateRegistrationService.selectZkCandidateRegistrationByIdNumber(idNumber);
        ZikaoCandidateRegistration zikaoExamList = zikaoCandidateRegistrationService.selectZikaoCandidateRegistrationByIdNumber(idNumber);
        Map<String, Object> result = new HashMap<>();
        result.put("ck_exam", ckExamList);
        result.put("zsb_exam", zsbExamList);
        result.put("gk_exam", gkExamList);
        result.put("zk_exam", zkExamList);
        result.put("zikao_exam", zikaoExamList);
        return success(result);
    }
}
